package com.holly.controller;

import com.holly.mapper.ClazzMapper;
import com.holly.pojo.Clazz;
import com.holly.pojo.ClazzQueryParam;
import com.holly.pojo.PageResultData;
import com.holly.pojo.Result;
import com.holly.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author holly
 * @create 2025-07-02 22:55
 */
@RequestMapping("/clazzs")
@Slf4j
@RestController
public class ClazzController {
    @Autowired
    private ClazzService clazzService;

    @GetMapping
    public Result page(ClazzQueryParam  param){
        log.info("分页查询所有班级信息，参数：{}",param);
        PageResultData<Clazz> pageResultData = clazzService.page(param);
        return Result.success(pageResultData);
    }
    @PostMapping
    public Result save(@RequestBody Clazz clazz){
        log.info("添加班级信息，参数：{}",clazz);
        clazzService.save(clazz);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id){
        log.info("根据班级id获取班级信息：{}",id);
        Clazz clazz = clazzService.getById(id);
        return Result.success(clazz);
    }

    @PutMapping
    public Result update(@RequestBody Clazz clazz){
        log.info("修改班级信息，参数：{}",clazz);
        clazzService.update(clazz);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("删除班级，参数：{}",id);
        clazzService.delete(id);
        return Result.success();
    }

    @GetMapping("/list")
    public Result list(){
        log.info("获取所有班级信息");
        List<Clazz> clazzList = clazzService.list();
        return Result.success(clazzList);
    }


}
